$(function () {
    $('#generalApproval_datagrid').datagrid({
        url:'/noRecive/list',
        fitColumns:true,
        height:'350',
        pagination:true,
        rownumbers:true,
        singleSelect:true,
        columns:[[
            {field:'orderBillNumber',title:'申请单号',width:100,align:'center',
                formatter: function(value,row,index){
                    console.log(row)
                    if(row.orderBillNumber){
                        return row.orderBillNumber
                    }else{
                        return ""
                    }
                }
            },
            {field:'c_name',title:'投保人名称',width:100,align:'center',
                formatter: function(value,row,index){
                    console.log(row)
                    if(row.beApply){
                        return row.beApply.realName
                    }else{
                        return ""
                    }
                }
            },
            {field:'cl_name',title:'被投保人名称',width:100,align:'center',
                formatter: function(value,row,index){
                    console.log(row)
                    if(row.client){
                        return row.client.realName
                    }else{
                        return ""
                    }
                }
            },
            {field:'carNumber',title:'车牌号',width:100,align:'center'},
            {field:',applyTime',title:'投保申请日期',width:140,align:'center',
                formatter: function(value,row,index){
                    console.log(row)
                    if(row.applyTime){
                        return row.applyTime
                    }else{
                        return ""
                    }
                }
            },
            {field:'p.name',title:'名称',width:100,align:'center',
                formatter: function(value,row,index){
                    console.log(row)
                    if(row.product){
                        return row.product.name
                    }else{
                        return ""
                    }
                }
            },
        ]]
    }),

    $('#noReciveDialog').dialog({
        width:400,
        height:400,
        closed:'true'
    })
})
function serach() {
    var ogName = $('#ogName').val();
    var parent_product_name = $('#parent_product_name').val();
    var apply_name = $('#apply_name').val()
    var apply_time_min = $('#apply_time_min').datebox('getValue')
    var apply_time_max = $('#apply_time_max').datebox('getValue')
    if(apply_time_max==""){
        apply_time_max = '01/01/2017'
    }
    if(apply_time_min==""){
        apply_time_min = '01/01/2099'
    }
    var insurancePolicyNumber = $('#insurancePolicyNumber').val()
    var carNumber = $('#carNumber').val()
    var be_apply_number = $('#be_apply_number').val()
    $('#generalApproval_datagrid').datagrid('load',{
        organizationName:ogName,
        produtName:parent_product_name,
        applyClientName:apply_name,
        minApplyTime:apply_time_min,
        maxApplyTime:apply_time_max,
        insurancePolicyNumber:insurancePolicyNumber,
        carNumber:carNumber,
        beApplyClientName:be_apply_number
    });
}
function reload(){
    $('#generalApproval_datagrid').datagrid('reload');
}
function fast_appravl_deal() {
    var selectedVal = $('#generalApproval_datagrid').datagrid('getSelected');
    if(selectedVal){
        var idval = selectedVal.insurancePolicyNumber;
        var url = $('#approval_reason').combobox('getValues');
        console.log(url);
        console.log(idval)
        window.location.href = url+'?insurancePolicyNumber='+idval;
    }else{
        $.messager.alert('温馨提示','请选择需要审批的条目','warning')
    }
}
function fast_approval(){
    var selected = $('#generalApproval_datagrid').datagrid('getSelected');
    if(selected){
        var val = selected.insurancePolicyNumber;
        window.location.href="/insuranceInfoChange?insurancePolicyNumber="+val
    }else{
        $.messager.alert('温馨提示',"请选择需要修改的条目","warning")
    }
}
function timeLine(){
    var selected = $('#generalApproval_datagrid').datagrid('getSelected');
    if(selected){
            $('#noReciveDialog').dialog('setTitle','承保流程')
            $('#noReciveDialog').dialog('open')
        $.get('/insuranceInfoChange/approvalByInsurancePolicyNumber',{insurancePolicyNumber:selected.insurancePolicyNumber},function(data){
            if(data.client){
                data['client.realName'] = data.client.realName;
            }
            if(data.employee){
               data['employee.name'] = data.employee.name
            }
            if(data.orderbill){
                data['orderbill.applyTime'] = data.orderbill.applyTime
            }
            $('#timeLine_form').form('load',data);
        })
    }else{
        $.messager.alert('温馨提示','请选择需要浏览的保单',"warning")
    }

}